<?php
namespace App\Repositories;
use App\Task;
class  TasksRepository
{
   public function create($request){
    Task::create([
        'name' => $request->name,
        'completion'=>(int) false,
        'project_id'=>$request->project
        ]);
   }
   public function find($id){
    return Task::findOrfail($id);
   }
   public function check($id){
    $task=$this->find($id);
    $task->update([
        'completion'=>(int)true,
    ]);
   }
   public function update($request, $id){
    $task=$this->find($id);
    $task->update([
        'name'=>$request->name,
        'project_id'=>$request->project_id,
    ]);
    // $task->save();
    }
    public function destroy($id){
        $task=$this->find($id);
        $task->delete();
    }
    public function todos(){
        return auth()->user()->tasks()->where('completion',0)->paginate(1);
    }
    public function done(){
        return auth()->user()->tasks()->where('completion',1)->paginate(5);
    }
    public function todoCount(){
        return auth()->user()->tasks()->where('completion',0)->count();
    }
    public function doneCount(){
        return auth()->user()->tasks()->where('completion',1)->count();
    }
    public function totalCount(){
        return auth()->user()->tasks()->count();
    }
    public function all(){
        return auth()->user()->tasks;
    }
}